//
//  NSString++.m
//  ihas
//
//  Created by Jpwang on 17/2/14.
//  Copyright © 2017年 Jpwang. All rights reserved.
//

#import "JPString.h"

@implementation NSString (encode)

+ (NSString*)encode:(NSString *)string{
    NSString *encodedString = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)string,NULL,NULL,kCFStringEncodingUTF8));
    return encodedString;
}

@end


@implementation NSString (md5)

+ (NSString *)md5:(NSString *) input {
    const char *cStr = [input UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_LONG length = (CC_LONG)strlen(cStr);
    CC_MD5(cStr, length, digest ); // This is the md5 call
    NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [output appendFormat:@"%02x", digest[i]];
    }
    return  output;
}

@end


@implementation NSString (ext)

- (NSString *)concat:(NSString *) string {
    return [NSString stringWithFormat:@"%@%@",self,string];
}

NSString *concat(NSString *str1, NSString *str2) {
    return [NSString stringWithFormat:@"%@%@",str1, str2];
}


NSString *trim(NSString *str) {
    return [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}

@end
